package cn.edu.abtu.scheduled;

import cn.edu.abtu.service.StatisticsDailyService;

import cn.edu.abtu.vo.ResponseData;
import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    //https://www.pppet.net/为cron表达式生成网址
    @Scheduled(cron = "0 0 2 * * ? ") //每天凌晨2点执行定时
    public void task() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        Date date = calendar.getTime();
        ResponseData responseData = statisticsDailyService.registerCount(simpleDateFormat.format(date));
    }

    public static void main(String[] args) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        Date date = calendar.getTime();
        System.out.println(simpleDateFormat.format(date));
    }

}
